import { createRouter, createWebHashHistory } from "vue-router";
export const Layout = () => import("@/components/Layout/index.vue");

const powerType = import.meta.env.VITE_POWER_TYPE; // 权限类型
/**
 * hidden: true                   如果为true，侧边栏显示，否则是为通用隐藏路由
 * alwaysShow: true               如果为true，将总显示
 *                                如果设置了,路由数量必须大于1
 * redirect: noRedirect           如果设置noRedirect，面包屑不重定向标题
 * meta : {
    role: 'admin'                 路由权限唯一标识
    title: 'title'                路由标题，面包屑展示标题
    icon: 'svg-name'              路由图标
    breadcrumb: false             如果为false，面包屑标题隐藏
  }
 */

// 静态路由

const constantRouters = [
  {
    path: "/",
    hide: true,
    name: "index",
    redirect: "/dashboard/index/",
  },
  {
    path: "/dashboard",
    name: "Dashboard",
    component: Layout,
    redirect: "/dashboard/index/",
    children: [
      {
        name: "Index",
        path: "index",
        component: () => import("@/views/dashboard/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/index.vue"),
  },
  // {
  //   path: "/register",
  //   name: "register",
  //   component: () => import("@/views/register/index.vue"),
  // },
  {
    hide: true,
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/404/index.vue'),
  },
];

// 动态路由
export const asyncRoutes = [
  {
    path: "/management",
    component: Layout,
    name: "Manage",
    meta: {
      title: "管理",
      role: "admin",
      icon: "logo",
    },
    children: [
      {
        path: "users",
        name: "management-users",
        meta: {
          title: "用户管理",
          role: "admin",
          icon: "user",
        },
        children: [
          {
            path: "userList",
            component: () =>
                import("@/views/management/users/userList/index.vue"),
            name: "management-users-userList",
            meta: {
              title: "用户权限",
              role: "admin",
              icon: "user-paint",
            },
          },
          {
            path: "userPermission",
            component: () =>
                import("@/views/management/users/userPermission/index.vue"),
            name: "management-users-userPermission",
            meta: {
              title: "角色管理",
              role: "admin",
              icon: "permission",
            },
          },
        ],
      },
    ],
  },
  {
    path: "/menu",
    component: Layout,
    name: "Menu",
    meta: {
      title: "菜单",
      role: "monitor",
      icon: "monitor",
    },
    children: [
      {
        path: "display",
        name: "menu-display",
        component: () => import("@/views/monitor/display/index.vue"),
        meta: {
          title: "我的菜单",
          icon: "message",
          role: "monitor",
        },
      },
      {
        path: "add",
        name: "menu-add",
        component: () => import("@/views/monitor/add/index.vue"),
        meta: {
          title: "添加菜品",
          icon: "message",
          role: "monitor",
        },
      },
      {
        path: "audit",
        name: "menu-audit",
        component: () => import("@/views/monitor/audit/index.vue"),
        meta: {
          title: "我的订单",
          icon: "message",
          role: "monitor",
        },
      }
    ],
  },
  // 重定向放最后
  {
    path: "/:pathMatch(.*)*",
    hidden: true,
    name: "404",
    component: () => import("@/views/404/index.vue"),
  },
];

const allRouter =
  powerType === "1"
    ? constantRouters.concat(asyncRoutes)
    : constantRouters;

export const router = createRouter({
  history: createWebHashHistory(),
  routes: allRouter,
});
